
$(document).ready(function() {
	var botao;
	var aoColumns = [
            { "sTitle": "CPF", "mDataProp": "cpf", "sClass": "right","bVisible": true , "sDefaultContent":""},
            { "sTitle": "Ramo de atuação", "mDataProp": "ramoAtuacaos","sWidth": "370px", "sClass": "right","bVisible": true , "sDefaultContent":"","bSortable": false, "isList":true, "insideDataProp": "descricao"},
            { "sTitle": "Idiomas", "mDataProp": "idiomas","sWidth": "370px", "sClass": "right","bVisible": true , "sDefaultContent":"","bSortable": false, "isList":true, "insideDataProp": "lingua.nome"},
            { "sTitle": "Publicações Cinetíficas", "mDataProp": "publicacoesCientificas","sWidth": "370px", "sClass": "right","bVisible": true , "sDefaultContent":"","bSortable": false, "isList":true, "insideDataProp": "referencia"},
            { "sTitle": "Experiências profissionais", "mDataProp": "experienciasProfissional","sWidth": "370px", "sClass": "right","bVisible": true , "sDefaultContent":"","bSortable": false, "isList":true, "insideDataProp": "funcao"},
            { "sTitle": "Formações Acadêmicas", "mDataProp": "formacoesAcademicas","sWidth": "370px", "sClass": "right","bVisible": true , "sDefaultContent":"","bSortable": false, "isList":true, "insideDataProp": "curso"},
            { "sTitle": "Nome", "mDataProp": "nome", "sClass": "right" ,"bVisible": true , "sDefaultContent":""},
            { "sTitle": "Agencia Bancária", "mDataProp": "agenciaBancaria","sType":"numeric", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Bairro Residencial", "mDataProp": "bairroResidencial", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Celular", "mDataProp": "celular", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "CEP", "mDataProp": "cepResidencial", "sClass": "right","bVisible": false , "sDefaultContent":""},
            { "sTitle": "Conta corrente", "mDataProp": "contaCorrente", "sClass": "right","bVisible": false , "sDefaultContent":""},
            { "sTitle": "Data de ingresso", "mDataProp": "dataIngresso","sType":"date", "sClass": "right","bVisible": false , "sDefaultContent":""},
            { "sTitle": "Data de nascimento", "mDataProp": "dataNascimento","sType":"date", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Email", "mDataProp": "email", "sClass": "right","bVisible": false , "sDefaultContent":""},
            { "sTitle": "Email profissional", "mDataProp": "emailProfissional", "sClass": "right","bVisible": false , "sDefaultContent":""},
            { "sTitle": "Endereço Residencial", "mDataProp": "enderecoResidencial", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Genero", "mDataProp": "genero", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Pai", "mDataProp": "pai", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Mãe", "mDataProp": "mae", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "NIS/PIS/PASEP", "mDataProp": "nisPisPasep","sType":"numeric", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Orgão expeditor", "mDataProp": "orgaoExpedidor", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Rg civil", "mDataProp": "rgCivil", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Rg profissional", "mDataProp": "rgProfissional", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Siape", "mDataProp": "siape","sType":"numeric", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Fax", "mDataProp": "telefoneFaxProfissional", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Fixo profissional", "mDataProp": "telefoneFixoProfissional", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Fixo residencial", "mDataProp": "telefoneFixoResidencial", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Banco", "mDataProp": "banco.nome", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Estado expeditor", "mDataProp": "estadoExpedidor.uf", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Graduação/Cargo", "mDataProp": "graduacaoCargo.nome", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Municipio Residencial", "mDataProp": "municipioResidencial.nome", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Naturalidade", "mDataProp": "naturalidade.nome", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            { "sTitle": "Ramo da segurança pública", "mDataProp": "ramoSegurancaPublica.generalizacaoEfetivo", "sClass": "right", "bVisible": false , "sDefaultContent":""},
            {"sTitle": "Opções", "mDataProp": "htmlControl","bSortable": false, "bVisible": true, "sWidth": "90px","sDefaultContent":"", 
				   "fnRender": function ( oObj ) {
						botao = "<button type=\"button\" class=\"printBtnpessoaDataGrid\" onclick=\"window.open('pessoas/curriculum/anexos?format=pdf&id="+oObj.aData.id+"','_blank')\" >Exportar para PDF</button>";
						botao+= "<button type=\"button\" class=\"printBtnpessoaDataGrid\" onclick=\"carregaDados(event, '"+id+"')\" >Carregar Dados</button>";
						return botao;
				  }
			  }
		];
		
	var id = "pessoaDataGrid";
	var url = "pessoas/bServerSideHql";
//	var table = 	" Pessoa as o ";
	var table = 	"";
	var where = " where o.tipoCadastroPessoa='BancoTalentos' ";
	var classe = "br.com.educa.modelo.pessoa.Pessoa";
	var arrString = 	JSON.stringify(aoColumns, function(key, val) {if (typeof val === 'function') { return val + '';} return val;});
	listServerSide(id, url, table, where,classe, arrString);
	
});

function carregaDados(event, idDataGrid){

	var clickedTr = $(event.target).parent("td").parent("tr").get(0);
  	var aTrs = $('#'+idDataGrid).dataTable().fnSettings().aoData;
  	var objetoSelecionado;
  	for(var i=0; i< aTrs.length; i++){
  		if(aTrs[i].nTr==clickedTr){
  			objetoSelecionado = aTrs[i]._aData;
  		}
  	}
  	carregaSelecaoBancoTalentos(objetoSelecionado);	
  	$('#modalDialog').dialog('destroy');
}

//function exportarParaPdf(event,idDataGrid,url,classe){
//	var clickedTr = $(event.target).parent("td").parent("tr").get(0);
//	var aTrs = $('#'+idDataGrid).dataTable().fnSettings().aoData;
//	var id;
//	for(var i=0; i< aTrs.length; i++){
//		if(aTrs[i].nTr==clickedTr){
//			id = aTrs[i]._aData.id;
//		}
//	}
//	window.open('arquivoes/showdoc/"+oObj.aData.arquivo.id+"','_blank')
//	window.location=url+id;
//}